function selectFileImage(fileObj) {
    var file = fileObj.files['0'];
    //图片方向角
    var Orientation = null;

    if (file) {
        console.log("正在上传,请稍后...");
        $("#sendimginfo").css("display","block");
        $("#sendimginfo p:first-child").html("正在处理图片");

        var rFilter = /^(image\/jpeg|image\/png|image\/jpg)$/i; // 检查图片格式
        console.log(file);
        //能获取到图片类型做判断 获取不到图片类型直接跳过
        if(file.type){
            if (!rFilter.test(file.type)) {
                $("#sendimginfo").css("display","none");
                alert("您的图片格式有误");
                var code="";
                for(var key in file){
                    code+=key+";";
                }
                //$("#contentword").val(code);
                return;
            }
        }
        // var URL = URL || webkitURL;
        //获取照片方向角属性，用户旋转控制
        EXIF.getData(file, function() {
            EXIF.getAllTags(this);
            Orientation = EXIF.getTag(this, 'Orientation');
        });
        var oReader = new FileReader();
        oReader.onload = function(e) {
            console.log("running");
            var image = new Image();
            image.src = e.target.result;
            var oldBase64=e.target.result;
            image.onload = function() {
                var expectWidth = this.naturalWidth;
                var expectHeight = this.naturalHeight;
                if (this.naturalWidth > this.naturalHeight && this.naturalWidth > 700) {
                    expectWidth = 700;
                    expectHeight = expectWidth * this.naturalHeight / this.naturalWidth;
                }
                else if (this.naturalHeight > this.naturalWidth && this.naturalHeight > 700) {
                    expectHeight = 700;
                    expectWidth = expectHeight * this.naturalWidth / this.naturalHeight;
                }
                var canvas = document.createElement("canvas");
                var ctx = canvas.getContext("2d");
                canvas.width = expectWidth;
                canvas.height = expectHeight;
                ctx.drawImage(this, 0, 0, expectWidth, expectHeight);

                var base64 = canvas.toDataURL("image/jpeg", 0.7);

                //如果方向角不为1，都需要进行旋转 added by lzk
                if(Orientation != "" && Orientation != 1){
                    var canvasRotateImage=new Image();
                    canvasRotateImage.src=base64;
                    canvasRotateImage.onload = function(){
                        switch(Orientation){
                            case 6://需要顺时针（向左）90度旋转
                                rotateImg(this,'left',canvas);
                                break;
                            case 8://需要逆时针（向右）90度旋转
                                rotateImg(this,'right',canvas);
                                break;
                            case 3://需要180度旋转
                                rotateImg(this,'right',canvas,2);//转两次
                                rotateImg(this,'right',canvas,2);
//                                    rotateImg(this,'right',canvas,2);//转两次
                                break;
                        }
                        base64 = canvas.toDataURL("image/jpeg", 0.7);
                        lastSendImgFtn(base64);
                    }
                }else{
                    lastSendImgFtn(base64);
                }
            };
        };
        oReader.readAsDataURL(file);
    }
}
function lastSendImgFtn(base64){
    $("#sendimginfo p:first-child").html("正在上传图片");
    $.ajax({
        type: "POST",
        url:  addimgurl,
        data: { "base64":base64, "type": ".jpg","flag":2},//flag:1表示头像，2普通照片
        success: function (data) {
            thisimgname=data.Data;
            var divheight=$(".modifier.image").eq(0).height();
            console.log(divheight);
            if(!imghash[thisimgname]){
                imghash[thisimgname]=thisimgname;
            }
            $("#sendimginfo").css("display","none");
            if(/answerpage.html/.test(location.href)){
                $("#questionbody").append("<div class='mainshowimgbox' style='height:21vw;width:21vw;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+thisimgname+"' data-img='"+thisimgname+"'><img src='"+imgurl+thisimgname+"'></div>");
                if($(".mainshowimgbox").length>=9){
                    $(".modifier.image").attr("class","modifier image toolbaricon cannot");
                    addimgbtn.style.display="none";
                }
            }
            else{
                $("<div class='mainshowimgbox' style='height:21vw;width:21vw;overflow:hidden;' onclick='showbigimg(this)' data-imgurl='"+thisimgname+"' data-img='"+thisimgname+"'><img src='"+base64+"'></div>").insertBefore("#questionbody .modifier.image");
                if($(".mainshowimgbox").length>=9){
                    $(imgbtn).css("display","none");
                }
            }
            $("#addimgbtn").val("");
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}
//对图片旋转处理 added by lzk
function rotateImg(img, direction,canvas,two) {
    //alert(img);
    //最小与最大旋转方向，图片旋转4次后回到原方向
    var min_step = 0;
    var max_step = 3;
    //var img = document.getElementById(pid);
    if (img == null)return;
    //img的高度和宽度不能在img元素隐藏后获取，否则会出错
    var height = img.height;
    var width = img.width;
    //var step = img.getAttribute('step');
    var step = 2;
    if(two==2){
        step=1;
    }
    if (step == null) {
        step = min_step;
    }
    if (direction == 'right') {
        step++;
        //旋转到原位置，即超过最大值
        step > max_step && (step = min_step);
    } else {
        step--;
        step < min_step && (step = max_step);
    }

    var degree = step * 90 * Math.PI / 180;
    var ctx = canvas.getContext('2d');
    switch (step) {
        case 0:
            canvas.width = width;
            canvas.height = height;
            ctx.drawImage(img, 0, 0);
            break;
        case 1:
            canvas.width = height;
            canvas.height = width;
            ctx.rotate(degree);
            ctx.drawImage(img, 0, -height);
            break;
        case 2:
            canvas.width = width;
            canvas.height = height;
            ctx.rotate(degree);
            ctx.drawImage(img, -width, -height);
            break;
        case 3:
            canvas.width = height;
            canvas.height = width;
            ctx.rotate(degree);
            ctx.drawImage(img, -width, 0);
            break;
    }
}